﻿using System;
using System.Collections.Generic;
using DTO;
using System.Data;
using System.Data.SqlClient;

namespace DAO
{
    public class DAOQuanLyMonHoc
    {
        public static DataTable DanhSachMonHoc()
        {
            try
            {
                return SQLDataProvider.ExecuteQueryString("Select MAMONHOC, TENMONHOC From MonHoc");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static DataTable DanhSachKhoiLop()
        {
            try
            {
                return SQLDataProvider.ExecuteQuery("sp_LietKeDanhSachKhoiLop",null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static DataTable MonHocKhoiLop()
        {
            try
            {
                return SQLDataProvider.ExecuteQuery("sp_LietKeMonHocKhoiLop",null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static DataTable TimKiemMonHoc(DTOMonHoc monhoc)
        {
            try
            {
                return SQLDataProvider.ExecuteQueryString("Select MAMONHOC, TENMONHOC From MonHoc where tenmonhoc like N'%" + monhoc.TenMonHoc + "%'");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static int ThemMonHoc(DTOMonHoc monhoc)
        {
            try
            {
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@TENMONHOC", monhoc.TenMonHoc));
                return SQLDataProvider.ExecuteNoneQuery("sp_ThemMonHoc", sqlParams);
            }
            catch (Exception ex)
            {
                throw ex;
            }  
        }

        public static int SuaTenMonHoc(DTOMonHoc monhoc)
        {
            try
            {
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@TENMONHOC", monhoc.TenMonHoc));
                sqlParams.Add(new SqlParameter("@MAMONHOC", monhoc.MaMonHoc));
                return SQLDataProvider.ExecuteNoneQuery("sp_SuaTenMonHoc", sqlParams);
            }
            catch (Exception ex)
            {
                throw ex;
            }  
        }

        public static int XoaMonHoc(DTOMonHoc monhoc)
        {
            try
            {
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MAMONHOC", monhoc.MaMonHoc));
                return SQLDataProvider.ExecuteNoneQuery("sp_XoaMonHoc", sqlParams);
            }
            catch (Exception ex)
            {
                throw ex;
            }  
        }

        public static DataTable LietKeMonHoc(DTOKhoiLop khoilop)
        {
            try
            {
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                if (khoilop.MaKhoiLop != null)
                    sqlParams.Add(new SqlParameter("@MAKHOILOP", khoilop.MaKhoiLop));
                else
                    sqlParams.Add(new SqlParameter("@MAKHOILOP", ""));
                return SQLDataProvider.ExecuteQuery("sp_LietKeMonHocKhoiLop", sqlParams);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static int ThemMonHocKhoiLop(DTOMonHocKhoiLop monhockhoilop)
        {
            try
            {
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MAMH", monhockhoilop.MaMH));
                sqlParams.Add(new SqlParameter("@MAKHOILOP", monhockhoilop.MaKL));
                return SQLDataProvider.ExecuteNoneQuery("sp_ThemMonHocKhoiLop", sqlParams);
            }
            catch (Exception ex)
            {
                throw ex;
            }  
        }

        public static int XoaMonHocKhoiLop(DTOMonHocKhoiLop monhockhoilop)
        {
            try
            {
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MAMH", monhockhoilop.MaMH));
                sqlParams.Add(new SqlParameter("@MAKHOILOP", monhockhoilop.MaKL));
                return SQLDataProvider.ExecuteNoneQuery("sp_XoaMonHocKhoiLop", sqlParams);
            }
            catch (Exception ex)
            {
                throw ex;
            }  
        }
    }
}
